package com.cwj.lab3.博客需要.链式前向星;
/**
 * 升级版链式前向星
 * 其功能和十字链表一样
 * */
public class Graph_star {
    static class Edge {
        int u;//起点
        int v;//尾点
        int val;//权重
        int next;//同起点的上一条边
        int pre;//同尾点的下一条边
    }

    Edge[] nums;
    int[] head;
    int[] end;
    int cnt = 0;

    void init(int v_num, int e_num) {
        nums = new Graph_star.Edge[e_num];
        head = new int[v_num];
        end = new int[v_num];
    }

    void addEdge(int u, int v, int val) {
        nums[cnt].u = u;
        nums[cnt].v = v;
        nums[cnt].val = val;
        nums[cnt].next = head[u];
        head[u] = cnt;
        nums[cnt].pre = end[v];
        end[v] = cnt;
        cnt += 1;
    }
}
/**
 * 传统链式前向星
 * */
class Graph_star_2 {
    static class Edge {
        int v;
        int val;
        int next;
    }

    Edge[] nums;//边表
    int[] head;
    int cnt = 0;

    void init(int v_num, int e_num) {
        nums = new Edge[e_num];
        head = new int[v_num];
    }

    void addEdge(int u, int v, int val) {
        nums[cnt].v = v;
        nums[cnt].val = val;
        nums[cnt].next = head[u];
        head[u] = cnt++;
    }
}



